package cn.touna.jss.modules.credit.service.impl;

import cn.touna.jss.modules.credit.entity.CreditNameAuthEntity;
import cn.touna.jss.modules.credit.mapper.CreditNameAuthEntityMapper;
import cn.touna.jss.modules.credit.service.AuthNameService;
import cn.touna.risk.api.domain.Response;
import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 实名认证
 */
@Service
public class AuthNameServiceImpl implements AuthNameService {

    private static final Logger logger = (Logger) LogManager.getLogger();

    @Autowired
    private CreditNameAuthEntityMapper creditNameAuthEntityMapper;


    public void saveAuthData(Response response) {
        try {
            JSONObject obj = JSONObject.parseObject(response.getData().toString());
            CreditNameAuthEntity entity = new CreditNameAuthEntity();
            entity.setIdNo((String) obj.get("idNo"));
            entity.setName((String) obj.get("name"));
            entity.setCompareStatus((String) obj.get("compareStatus"));
            entity.setCompareDesc((String) obj.get("compareStatusDesc"));
            creditNameAuthEntityMapper.insert(entity);
        } catch (Exception e) {
            logger.error("【保存授权认证】保存认证记录出现异常，data:" + response.getData(), e);
        }
        return;

    }


    @Override
    public CreditNameAuthEntity queryNameAuth(String idCard, String name) {
        try {
            return creditNameAuthEntityMapper.selectObject(idCard, name);
        } catch (Exception e) {
            logger.info("查询实名认证异常:{}", e);
            return null;
        }

    }

}
